//
//  AppDelegate.m
//  New
//
//  Created by 才诗琦 on 16/1/16.
//  Copyright © 2016年 www.lanou3g.com. All rights reserved.
//

#import "AppDelegate.h"
#import "LoginViewController.h"
#import <MMDrawerController/UIViewController+MMDrawerController.h>


#import "LgVC.h"
@interface AppDelegate ()
//<UITabBarDelegate>
@property(nonatomic, retain)LoginViewController *leftVC;
@end

@implementation AppDelegate
- (void)dealloc
{
//    [super dealloc];
//    [self.rootVC release];
//    [self.navi release];
//    [self.qaVC release];
////    [self.qavi release];
//    [self.readVC release];
//    [self.revi release];
//    [self.videoVC release];
//    [self.videvi release];
//    [self.moreVC release];
//    [self.movi release];

//    [_window release];
}
//
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _window.backgroundColor = [UIColor whiteColor];
    [_window makeKeyAndVisible];

        
    
    
    //    [self.drawerController setRestorationIdentifier:@"MMDrawer"];
    
    
    
    
    // Override point for customization after application launch.
  //
// //
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    [SVGloble shareInstance].globleWidth = screenRect.size.width ; //屏幕宽度
    [SVGloble shareInstance].globleHeight = screenRect.size.height;  //屏幕高度（无顶栏）
//    [SVGloble shareInstance].globleAllHeight = screenRect.size.height-50;  //屏幕高度（有顶栏）

//    
//    tabBar
    //创建标签控制器
    UITabBarController *tabBar = [[UITabBarController alloc] init];
    tabBar.tabBar.barStyle = UIBarStyleDefault;
    tabBar.tabBar.translucent = NO;
      //24小时
    
    self.rootVC = [[TFViewController alloc] init];
    self.navi = [[UINavigationController alloc] initWithRootViewController:self.rootVC];
   
    self.rootVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Oneday" image:[UIImage imageNamed:@"24"] tag:1000];
    [self setNavigBa:@"Oneday" VC:self.rootVC];
    
    //问吧
   self.qaVC = [[QandAViewController alloc] init];
   self.qavi = [[UINavigationController alloc] initWithRootViewController:self.qaVC];
    self.qaVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Q&A" image:[UIImage imageNamed:@"ask"] tag:2000];
    [self setNavigBa:@"问吧" VC:self.qaVC];
    //QSTP科技园
    self.readVC = [[ReadViewController alloc] init];
   self.revi = [[UINavigationController alloc] initWithRootViewController:self.readVC];
    
    self.readVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"QSTP" image:[UIImage imageNamed:@"kejidongtai-2"] tag:3000];
    
    [self setNavigBa:@"科技" VC:self.readVC];
    
    self.videoVC = [[VideoViewController alloc] init];
   self.videvi = [[UINavigationController alloc] initWithRootViewController:self.videoVC];
    self.videoVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"video" image:[UIImage imageNamed:@"video"] tag:4000];
    [self setNavigBa:@"视频" VC:self.videoVC];
    
  
    //TabBar视图
    tabBar.viewControllers = @[self.navi, self.qavi,  self.revi, self.videvi ];
    tabBar.tabBar.tintColor = [UIColor redColor];
//    tabBar.tabBar.backgroundImage = [UIImage imageNamed:@"6"];
//    设置根视图
//    self.window.rootViewController =tabBar;
//    内存管理

    
//    LoginViewController *leftVC = [[[LoginViewController alloc] init] autorelease];
  self.leftVC = [[LoginViewController alloc] init];
    self.navi = [[[UINavigationController alloc] initWithRootViewController:_leftVC] autorelease];
    self.mmDrawer = [[MMDrawerController alloc] initWithCenterViewController:tabBar leftDrawerViewController:self.leftVC];

    
    // 抽屉最大偏移量
    [self.mmDrawer setMaximumLeftDrawerWidth:270.0];
    
    // 手势实现抽屉的拉伸和收回
    [self.mmDrawer setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    [self.mmDrawer setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    

    
    self.window.rootViewController = _mmDrawer;
    [self.rootVC release];
    [self.navi release];
    [self.qaVC release];
    [self.qavi release];
    [self.readVC release];
    [self.revi release];
    [self.videoVC release];
    [self.videvi release];
   
    [_window release];
    return YES;
}

- (void)setNavigBa:(NSString *)title
                VC:(UIViewController *)VC
{
    VC.navigationItem.title = title;
//    
    VC.navigationController.navigationBar.translucent = NO;
     [VC.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Nav"] forBarMetrics:UIBarMetricsDefault];
    //标题栏左右按钮
    VC.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"user"] style:UIBarButtonItemStylePlain target:self action:@selector(left:)] autorelease];
    VC.navigationController.navigationBar.tintColor = [UIColor blackColor];
    
    
   VC.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"sou"] style:UIBarButtonItemStylePlain target:self action:@selector(right:)] autorelease];
    
//    [ VC.navigationItem.leftBarButtonItem setupLeftMenuButton:(UIViewController *)VC];
//    [VC.navigationItem.leftBarButtonItem animated:YES];

  
}


- (void)left:(id)ba
{
    [_rootVC.mm_drawerController toggleDrawerSide:(MMDrawerSideLeft) animated:YES completion:^(BOOL finished) {
           }];

}

-(void)right:(UIBarButtonItem *)ba
{
    
    SousuoViewController *sousuo = [[SousuoViewController alloc] init];
    
    [_rootVC.navigationController pushViewController:sousuo animated:YES];
   
}

//- (void)setNavigSeg:(UISegmentedControl *)seg
//                VC:(UIViewController *)VC
//{
//    [VC.navigationController.navigationBar addSubview:seg];
////    VC.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
//    VC.navigationController.navigationBar.translucent = NO;
//    
//    VC.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"dingyue"] style:UIBarButtonItemStylePlain target:self action:@selector(rightY:)] autorelease];
//}


//-(void)rightY:(UIBarButtonItem *)ba
//{
//    
//}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
